package ParticiplePkg;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

import org.wltea.analyzer.IKSegmentation;
import org.wltea.analyzer.Lexeme;
import org.wltea.analyzer.dic.Dictionary;


/**
 * 用IK分词
 * @author duyf
 *
 */

public class IkParticiple implements Participle {

	
	public String[] participle(String srcStr) {
		StringReader reader = new StringReader(srcStr); 
	    IKSegmentation ik = new IKSegmentation(reader,true);//当为true时，分词器进行最大词长切分 
	    Lexeme lexeme = null; 
	    Dictionary dic=Dictionary.getInstance();
	    //添加停词
	   /* List<String> listStopwords=new ArrayList<String>();
	    listStopwords.add("java");
	    dic.loadExtendStopWords(listStopwords);*/
	    //添加主词 
	    List<String> listwords=new ArrayList<String>();
	    listwords.add("感冒解毒胶囊");
	    dic.loadExtendWords(listwords);
	    try {
	    	List<String> strList=new ArrayList<String>();
			while((lexeme = ik.next())!=null){
				strList.add(lexeme.getLexemeText());
			}
			return strList.toArray(new String[strList.size()]);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return null;
	}

}
